package com.highveldsky.appengine.xmppplay;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.xmpp.Presence;
import com.google.appengine.api.xmpp.XMPPService;
import com.google.appengine.api.xmpp.XMPPServiceFactory;


@SuppressWarnings("serial")
public class PresenceHandler extends HttpServlet {

	private static final Logger log = Logger.getLogger(PresenceHandler.class.getName());

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		log.info("Presence info received");
		
		// In the handler for _ah/xmpp/presence/*
		XMPPService xmppService = XMPPServiceFactory.getXMPPService();
		Presence presence = xmppService.parsePresence(req);

		String ptype = "";
		String pshow = "";
		if (presence.getPresenceType()!=null) ptype = presence.getPresenceType().name();
		if (presence.getPresenceShow()!=null) pshow = presence.getPresenceShow().name();
		
		log.info(presence.getFromJid().getId() +": "+ptype+": "+pshow);
		
		
		
	}

}
